package com.sxy.web.response; /**
 * @author 宋鑫宇
 * @version 1.0
 * 相应字符数据：设置字符数据的响应体
 */

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/resp3")
public class ResponseDemo03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置头信息
//        response.setHeader("content-type","text/html");会乱码
        response.setContentType("text/html;charset=utf-8");
        //1.获取对应的字符输出流
        PrintWriter writer = response.getWriter();


        //响应字符数据，中文会乱码,需要设置 response.setContentType("text/html;charset=utf-8");
        writer.write("李四");
        writer.write("<h1>aaa</h1>");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
